home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tricks of the Mac Game Programming Gurus
/
TricksOfTheMacGameProgrammingGurus.iso
/
Book Chapters
/
05 - User Interaction
/
CheckKey
/
CheckKey.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-03-07
|
953b
|
53 lines
#include <stdio.h>
static Boolean CheckKey(short keyCode)
{
KeyMap myKeyMap;
short byteIndex;
char theByte, theBit;
char *thePointer;
GetKeys(myKeyMap);
byteIndex = keyCode >> 3;
thePointer = (char *)&myKeyMap[0];
theByte = *(char *)(thePointer + byteIndex);
theBit = 1L<<(keyCode & 7);
return ( (theByte & theBit) != 0 );
return ( ( (myKeyMap[keyCode >> 3]) & (1L<<(keyCode & 7))) != 0);
} /*CheckKey*/
/* Standard inits */
static void InitToolbox(void) {
InitGraf (&qd.thePort);
InitFonts ();
FlushEvents (everyEvent,0);
InitWindows ();
InitMenus ();
TEInit ();
InitDialogs (nil);
InitCursor ();
} /*InitToolbox*/
main()
{
short i;
KeyMap myKeyMap;
InitToolbox();
printf("Hit a key to display its key code.\n");
while (!Button())
{
for (i=0; i<=127; i++)
if (CheckKey(i))
{
GetKeys(myKeyMap);
printf("Code: %d Map: %lx %lx %lx %lx\n", i,myKeyMap[0],myKeyMap[1],myKeyMap[2],myKeyMap[3]);
}
}
}